<?php
/**
* @version		$Id: pdf.php 14401 2010-01-26 14:10:00Z louis $
* @package		Joomla.Framework
* @subpackage	Document
* @copyright	Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();

/**
 * DocumentPDF class, provides an easy interface to parse and display a pdf document
 *
 * @package		Joomla.Framework
 * @subpackage	Document
 * @since		1.5
 */
class JDocumentPDF extends JDocument
{
	var $_engine	= null;

	/**
	 * Class constructore
	 *
	 * @access protected
	 * @param	array	$options Associative array of options
	 */
	function __construct($options = array())
	{
		parent::__construct($options);

		//set mime type
		$this->_mime = 'application/pdf';

		//set document type
		$this->_type = 'pdf';

		/*
		 * Create the pdf document
		 */
		jimport('mpdf50.mpdf');
		
		$this->_engine = new mPDF($mode='',
					  $format='A4',
					  $default_font_size=0,
					  $default_font='',
					  $mgl=15,
					  $mgr=15,
					  $mgt=14,
					  $mgb=16,
					  $mgh=9,
					  $mgf=9, 
					  $orientation='P'); 
	}


	/**
	 * Render the document.
	 *
	 * @access public
	 * @param boolean 	$cache		If true, cache the output
	 * @param array		$params		Associative array of attributes
	 * @return 	The rendered data
	 */
	function render( $cache = false, $params = array())
	{
		//ini_set ("memory_limit", "128M");
		$mpdf = &$this->_engine;
		//$mpdf->simpleTables = true;
		//$mpdf->packTableData = true;

		$mpdf->SetFooter(array(
			'L' => array(
				'content' => 'Wydrukowano @ '.date("Y-m-d H:i:s"),
				'font-family' => 'monospace',
				'font-style' => '',
				'font-size' => '9',
				),
			'R' => array(
				'content' => '{PAGENO}/{nb}',
				'font-family' => 'serif',
				'font-style' => 'BI',
				'font-size' => '11',	/* gives default */
				),
			'line' => 0,		/* 1 to include line below header/above footer */
			), 'O'	/* defines footer for odd Pages */
		);
		
		// LOAD a stylesheet
		$stylesheet = file_get_contents(JPATH_THEMES.'/khepri/css/general_pdf.css');
		$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text

		$mpdf->WriteHTML($this->getBuffer(),2);
		$data = $mpdf->Output();
		
		// Set document type headers
		parent::render();

		//JResponse::setHeader('Content-Length', strlen($data), true);

		JResponse::setHeader('Content-disposition', 'inline; filename="Ewidenja urządzeń.pdf"', true);

		//Close and output PDF document
		return $data;
	}
}